package cn.stylefeng.guns.modular.demos.dto;

import org.springframework.util.DigestUtils;

import lombok.Data;

@Data
public class KllHBDto {
	
	private String  ver;// 	版本号，固定为1
	private String wid;//: 	授权在平台的公众号ID（不清楚可跟客服咨询）
	private int count; //要生成的口令个数
	private String type; //要生成的口令类型 0为字母+数字，1为纯数字，2为纯字母
	private int length;  //要生成的口令长度
	private String maxmoney; //口令红包单个最大金额，单位：分
	private String minmoney; //口令红包单个最小金额，单位：分
	private String totalmoney; //此次生成分配的总金额，单位：分
	private String reqtick;//: 	(必填)请求时间戳，单位为秒，与北京标准时间误差不能超过30秒
	private String sign;//: 	(必填)参数验证签名 md5(ver+wid+count+type+length+maxmoney+minmoney+totalmoney+reqtick+apikey)，共32字节，字母都为小写
	

	/*
	 * 
	 http://www.yaoyaola.cn/index.php/wechat2/getcodes?
	 ver=1&wid=11976&count=6&type=0&length=6&maxmoney=1000&minmoney=600&totalmoney=4800&reqtick=1585752769&sign=714b33da9578fb44a664371db2d8e0da
	 
示例：
http://www.yaoyaola.cn/index.php/wechat2/getcodes?
ver=1&wid=33&count=1&type=0&length=6&maxmoney=100&minmoney=100&totalmoney=100&reqtick=1514947023&sign=13a4e9e3c425ba918340bccd2d45549e
生成1个口令，总金额1元，最大1元，最小1元，口令类型为字母+数字，长度为6

调用成功返回：
{"errcode":"0","errmsg":"success","codelist":[{"code":"wT390Z","money":"100"}]}

返回参数说明：
codelist：生成的口令数组
code：口令码
money：红包金额，单位：分
	 */
	
	
	public String toForm() {
		String form = "";
		
		//必选参数
		form += "ver=";
		form += ver;
		form += "&";
		
		form += "wid=";
		form += wid;
		form += "&";
		
		form += "count=";
		form += String.valueOf(count);
		form += "&";
		
		form += "type=";
		form += type;
		form += "&";
		
		form += "length=";
		form += String.valueOf(length);
		form += "&";
		
		form += "maxmoney=";
		form += maxmoney;
		form += "&";
		
		form += "minmoney=";
		form += minmoney;
		form += "&";
		
		form += "totalmoney=";
		form += totalmoney;
		form += "&";
		
		form += "reqtick=";
		form += reqtick;
		form += "&";
		
		
		form += "sign=";
		form += sign;
		form += "&";
		
		form = form.substring(0, form.length()-1);
		
		return form;
	}
	
	
	public String md5(String apikey) {
		//ver+wid+count+type+length+maxmoney+minmoney+totalmoney+reqtick+apikey
		String raw = "";
		
		raw += ver;
		raw += wid;
		raw += String.valueOf(count);
		raw += type;
		raw += String.valueOf(length);
		raw += maxmoney;
		raw += minmoney;
		raw += totalmoney;
		raw += reqtick;
		
		raw += apikey;
		
		return DigestUtils.md5DigestAsHex(raw.getBytes());
	}
}
